package com.wangsd.common.exception;

import com.wangsd.common.basicbean.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public Object handleException(Exception e, HttpServletRequest req) {
        log.error("通用异常：", e);
        return Result.fail("通用异常，请联系管理员");
    }

    @ExceptionHandler(BusinessException.class)
    public Object handleException(BusinessException e, HttpServletRequest req) {
        log.error("业务异常：", e);
        return Result.fail("业务异常：" + e.getMsg());
    }
}
